package com.motu.monstercity.server.game.logic;

import com.motu.monstercity.server.game.userdata.UserEvent;
import com.motu.monstercity.server.game.userdata.UserOnlineEvent;
import com.motu.monstercity.server.game.userdata.UserOnlineEventInfo;
import com.motu.vertx.module.utility.model.EntityManager;
import com.motu.vertx.module.utility.model.Model;

import java.util.ArrayList;
import java.util.List;

public class EventUserData extends EventBaseData {

    public static UserOnlineEventInfo getUserOnlineEventInfo(long userId) {
        return (UserOnlineEventInfo) EntityManager.getUniqueEntity(UserOnlineEventInfo.class, userId);
    }

    public static UserOnlineEvent getUserOnlineEvent(long userId, long id) {
        Model model = EntityManager.getEntity(UserOnlineEvent.class, userId, id);
        if (model != null) {
            return (UserOnlineEvent) model;
        }
        return null;
    }

    public static List<UserOnlineEvent> getUserOnlineEventList(long userId) {
        List<Model> modelList = EntityManager.getEntityList(UserOnlineEvent.class, userId);
        List<UserOnlineEvent> userOnlineEventList = new ArrayList<>();
        if (modelList.isEmpty()) {
            return userOnlineEventList;
        }
        for (Model model : modelList) {
            userOnlineEventList.add((UserOnlineEvent) model);
        }
        return userOnlineEventList;
    }

    public static long getOnlineEventCount(long userId) {
        return EntityManager.getEntityCount(UserOnlineEvent.class, userId);
    }

    public static List<UserEvent> getUserEventList(long userId) {
        List<Model> modelList = EntityManager.getEntityList(UserEvent.class, userId);
        List<UserEvent> userEventList = new ArrayList<>();
        if (modelList.isEmpty()) {
            return userEventList;
        }
        for (Model model : modelList) {
            userEventList.add((UserEvent) model);
        }
        return userEventList;
    }

    public static UserEvent getUserEvent(long userId, long id) {
        Model model = EntityManager.getEntity(UserEvent.class, userId, id);
        if (model != null) {
            return (UserEvent) model;
        }
        return null;
    }

}
